<template>
  <section class="tt-list">
    <div class="tt-list-item">
      <a href="#">
        <div class="image-box"><img :src="path" alt="" /></div>
        <div class="content-box">
          <div class="title_box">
            {{ title }}
          </div>
          <div class="new_price">
            <span>￥{{ price }}</span>
          </div>
          <div class="vip_price">
            <span>￥{{ vip_price }}</span>
            <img
              src=""
              alt=""
            />
            <span class="count">已售出{{ count }}{{ unit_name }}</span>
          </div>
        </div>
        <div class="cart-box">
          <i class="bi bi-cart3"></i>
        </div>
      </a>
    </div>
  </section>
</template>

<style lang="less" scoped>
@import "../../assets/less/variable.less";
.tt-list {
  background-color: #fff;
  padding: @padding2;
  padding-top: 0;
  .tt-list-item {
    padding-top: 0px;
    padding-bottom: 0px;
    a {
      display: block;
      width: 100%;
      position: relative;
      &::after {
        content: "";
        display: block;
        clear: both;
      }
    }
  }
  .image-box {
    float: left;
    width: 90px;
    height: 100px;
    line-height: 100px;
    text-align: center;
    overflow: hidden;
    img {
      width: 90px;
      vertical-align: middle;
    }
  }
  .content-box {
    float: left;
    font-size: 16px;
    width: calc(100% - 90px);
    padding-bottom: 10px;
    border-bottom: 1px solid #f0f0f0;
    .title_box {
      padding-left: @padding1;
      box-sizing: border-box;
      width: 100%;
      height: 32px;
      line-height: 32px;
      font-size: 16px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .new_price {
      padding-left:  @padding1;
      box-sizing: border-box;
      margin-top: 10px;
      font-size: 16px;
      color: @color3;
      font-weight: bold;
    }
    .vip_price {
      padding-left:  @padding1;
      box-sizing: border-box;
      margin-top: 5px;
      font-size: 13px;
      span {
        vertical-align: middle;
      }
      img {
        width: 28px;
        margin: 0 10px 0 5px;
        vertical-align: middle;
      }
      .count {
        color: #666;
      }
    }
  }
  .cart-box {
    position: absolute;
    right: 10px;
    bottom: 10px;
    width: 30px;
    height: 30px;
    color: @color3;
    text-align: center;
    line-height: 30px;
    font-size: 20px;
    border: 1px solid @color3;
    border-radius: 50%;
  }
}
</style>

<script>
export default {
  props: {
    itemObj: {
      type: Object,
    },
  },
  watch: {
    itemObj: {
      deep: true,
      immediate: true,
      handler: function (option) {
        //  console.log(option,'数据来源');
        this.price = option.price;
        this.vip_price = option.vip_price;
        this.count = option.sales;
        this.unit_name = option.unit_name;
        this.title = option.text;
        // 针对图片 找不到资源
        let src = option.path;
        let img = new Image();
        img.src = src;
        img.onload = () => {
          this.path = src;
        }
      },
    },
  },
  data() {
    return {
      path: require("../../assets/loading.gif"),
      count: 616,
      price: "00.00",
      vip_price: "00.01",
      unit_name: "件",
      title: "标题",
    };
  },
};
</script>